<?php

namespace Admin\Form;
use Base\InputFilter\ProvidesEventsInputFilter;
use User\Options\RegistrationOptionsInterface;

class CreateUserFormFilter extends ProvidesEventsInputFilter
{
    const MESSAGE_EMPTY = 'Thông tin bắt buộc';
    const MESSAGE_VALID = 'không đúng định dạng';

    public function __construct($emailValidator , RegistrationOptionsInterface $options)
    {
        $this->setOptions($options);
        $this->emailValidator = $emailValidator;

       $this->add(array(
           'name'       => 'firstname',
           'required'   => true,
           'filters' => array(
               array('name' => 'StripTags') ,
               array('name' => 'StringTrim') ,
           ),
           'validators' => array(
               /*array(
                   'name' => 'NotEmpty',
                   'options' => array(
                       'messages' => array(
                           \Zend\Validator\NotEmpty::IS_EMPTY => static::MESSAGE_EMPTY,
                       ),
                   ),
               ),*/
               array(
                   'name' => 'StringLength' ,
                   'options' => array(
                       'encoding' => 'UTF-8' ,
                       'min' => 2 ,
                       'max' => 50 ,
                       /*'messages' => array(
                           'stringLengthTooShort' => 'fisrtname tu 2 ki tu tro len',
                           'stringLengthTooLong' => 'fisrtname phai nho hon 50 ki tu.',
                       )*/
                   ) ,
               ),
           ),
       ));


       $this->add(array(
           'name'       => 'lastname',
           'required'   => true,
           'filters' => array(
               array('name' => 'StripTags') ,
               array('name' => 'StringTrim') ,
           ),
           'validators' => array(
               /*array(
                   'name' => 'NotEmpty',
                   'options' => array(
                       'messages' => array(
                           \Zend\Validator\NotEmpty::IS_EMPTY => static::MESSAGE_EMPTY,
                       ),
                   ),
               ),*/
               array(
                   'name'    => 'StringLength',
                   'options' => array(
                       'encoding' => 'UTF-8' ,
                       'min' => 2,
                       'max' => 50,
                   ),
                   /*'messages' => array(
                       'stringLengthTooShort' => 'lastname tu 2 ki tu tro len',
                       'stringLengthTooLong' => 'lastname phai nho hon 50 ki tu.',
                   )*/
               ),
               //$this->usernameValidator,
           ),
       ));
	
	
       $this->add(array(
           'name'       => 'email',
           'required'   => true,
           'validators' => array(
               /*array(
                   'name' => 'NotEmpty',
                   'options' => array(
                       'messages' => array(
                           \Zend\Validator\NotEmpty::IS_EMPTY => static::MESSAGE_EMPTY,
                       ),
                   ),
               ),*/
               array(
                   'name' => 'EmailAddress',
                   'options' => array(
                       /*'messages' => array(
                            'emailAddressInvalidFormat' => 'email khong dung dinh dang'
                           //\Zend\Validator\NotEmpty::IS_EMPTY => 'Email address is required',
                       )*/
                   )
               ),
               //$this->emailValidator
           ),
       ));

       $this->add(array(
           'name'       => 'password',
           'required'   => true,
           'filters'    => array(array('name' => 'StringTrim')),
           'validators' => array(
               array(
                   'name' => 'NotEmpty',
                   /*'options' => array(
                       'messages' => array(
                           \Zend\Validator\NotEmpty::IS_EMPTY => 'password không được để trống.',
                       ),
                   ),*/
               ),
               array(
                   'name'    => 'StringLength',
                   'options' => array(
                       'min' => 6,
                       /*'messages' => array(
                          'stringLengthTooShort' => 'password phai it nhat la 6 ki tu.',
                       ),*/
                   ),
               ),
           ),
       ));

       $this->add(array(
           'name'       => 'password_verify',
           'required'   => true,
           'filters'    => array(array('name' => 'StringTrim')),
           'validators' => array(
               array(
                   'name'    => 'StringLength',
                   'options' => array(
                       'min' => 6,
                   ),
               ),
               array(
                   'name'    => 'Identical',
                   'options' => array(
                       'token' => 'password',
                       /*'messages' => array(
                           'notSame' => "password khong khop.",
                           'missingToken' => "password khong khop.",
                       )*/
                   ),
               ),
           ),
       ));
       $this->getEventManager()->trigger('init', $this);

    }

    public function getEmailValidator()
    {
        return $this->emailValidator;
    }

    public function setEmailValidator($emailValidator)
    {
        $this->emailValidator = $emailValidator;
        return $this;
    }

    public function getUsernameValidator()
    {
        return $this->usernameValidator;
    }

    public function setUsernameValidator($usernameValidator)
    {
        $this->usernameValidator = $usernameValidator;
        return $this;
    }


    /**
     * set options
     *
     * @param RegistrationOptionsInterface $options
     */
    public function setOptions(RegistrationOptionsInterface $options)
    {
        $this->options = $options;
    }

    /**
     * get options
     *
     * @return RegistrationOptionsInterface
     */
    public function getOptions()
    {
        return $this->options;
    }
} 